//
//  FunctionCell.swift
//  Employee
//
//  Created by swordjoy on 2017/3/23.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class FunctionCell: UITableViewCell {
  
  static var height: CGFloat { return 120.0 }
  
  static var identifier: String { return "FunctionCell.swxc" }

  var functionImage: UIImage?  {
    didSet {
      guard let temp = functionImage else { return }
      imageV.image = temp
    }
  }
  
  var title: String? {
    didSet {
      guard let temp = title else { return }
      titleLabel.text = temp
    }
  }
  
  fileprivate var containerV: UIView!
  fileprivate var imageV: UIImageView!
  fileprivate var titleLabel: UILabel!
  
  // MARK: - life cycle
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    
    backgroundColor = UIColor.clear
    selectionStyle = .none
    
    create()
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

// MARK: - fileprivate

extension FunctionCell {
  fileprivate func create() {
    containerV = UIView()
    contentView.addSubview(containerV)
    containerV.backgroundColor = UIColor.white
    containerV.snp.makeConstraints { (make) in
      make.left.equalTo(self).offset(10)
      make.right.equalTo(self).offset(-10)
      make.top.equalTo(self).offset(2.5)
      make.bottom.equalTo(self).offset(-2.5)
    }
    containerV.layer.cornerRadius = 3
    containerV.clipsToBounds = true
    
    imageV = UIImageView()
    //imageV.contentMode = .scaleAspectFit
    containerV.addSubview(imageV)
    imageV.snp.makeConstraints { (make) in
      make.left.equalTo(36)
      make.centerY.equalToSuperview()
      //make.width.equalTo(48)
      //make.height.equalTo(48)
    }
    
    titleLabel = UILabel()
    containerV.addSubview(titleLabel)
    titleLabel.font = GlobalConfig.system16Font
    titleLabel.snp.makeConstraints { (make) in
      make.left.equalTo(imageV.snp.right).offset(26)
      make.centerY.equalToSuperview()
    }
  }
}
